home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Misc / Digital_Almanac / Install / Developer / example.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  1.6 KB  |  59 lines

  1. #include <clib/dos_protos.h>
  2. #include <clib/exec_protos.h>
  3. #include <stdio.h>
  4. #include "damessage.h"
  5. #include <math.h>
  6.  
  7. static double PI180; /* rad -> deg */
  8.  
  9. void main()
  10. {
  11. PI180=atan(1)*4/180;
  12. if(!FindPort("DA_Port")) /* Make sure, port doesn't exist twice !! */
  13.     {
  14.     struct MsgPort *daport;
  15.     if(daport=CreateMsgPort()) /* Create the MsgPort */
  16.         {
  17.         ULONG signals;
  18.         daport->mp_Node.ln_Name="DA_Port"; /* The name of the MsgPort and make it public */
  19.         AddPort(daport);
  20.         signals=(1<<daport->mp_SigBit)|SIGBREAKF_CTRL_C; /* Check for MsgPort and User-Break */
  21.         for(;;)
  22.             {
  23.             ULONG sigs;
  24.             struct DAMessage *msg;
  25.             sigs=Wait(signals); /* Wait for messages */
  26.             if(sigs&SIGBREAKF_CTRL_C) /* User break ? Then exit */
  27.                 {
  28.                 puts("***Break");
  29.                 break;
  30.                 }
  31.             while(msg=(struct DAMessage *)GetMsg(daport)) /* Get message sent from DA */
  32.                 {
  33.                 printf("R:%f D:%f\n",msg->dam_RA/PI180,msg->dam_Decl/PI180);
  34.                 printf("A:%f H:%f\n\n",msg->dam_Az/PI180,msg->dam_Ho/PI180);
  35.                 ReplyMsg((struct Message *)msg); /* Reply the message. Absolutely necessary ! */
  36.                 }
  37.             }
  38.         Forbid(); /* Disable multi-tasking to prevent DA accessing the port */
  39.         RemPort(daport); /* Cleanup stuff */
  40.         DeleteMsgPort(daport);
  41.         Permit();
  42.         }
  43.     }
  44. else puts("Error: Public port 'DA_Port' already exists.");
  45. }
  46.  
  47. void wbmain(struct WBStartup *msg)
  48. {
  49. /*
  50. Warning !! This is a hack to redirect the output to a CON, when started from Workbench !
  51. It works perferct with Maxon C++.
  52. You can easily adapt this part for other compilers.
  53. */
  54.  
  55. if(!freopen("CON:////Digital Almanac II - Test Output/CLOSE","r+",stdout)) return;
  56. stdin->Filehandle=stdout->Filehandle;
  57. main();
  58. }
  59.